<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
	<head>
		<title>发布闲置商品</title>
	</head>
	<body>
		<!-- self_info -->
		<div class="grzxbj">
			<!-- release-goods -->
			<div class="selfinfo center release-goods">
				<fieldset class="layui-elem-field">
				  <legend class="elem-title">发布闲置商品</legend>
				  <!-- layui-field-box -->
				  <div class="layui-field-box">
				  	<!-- release-goods-left -->
				  	<div class="release-goods-left">
				  		<!-- selected-type -->
				  		<div class="selected-type">
				  			<p>找不到商品分类？请输入商品名关键字进行搜索</p>
				  			<input type="search" placeholder="搜索商品类目">
				  			<button type="button" id="selected-buttom">搜索</button>
				  			<div class="pipei-type">
				  				
				  			</div>
				  		</div><!-- selected-type -->
				  		
				  		<!-- release-goods-shuoming -->
				  		<div class="release-goods-shuoming">
				  			<p>发布闲置商品注意点：</p>
				  			<p><span>商品标题：</span>商品标题尽可能包含该商品名称关键词（比如商品第三级类目），方便用户搜索到该商品</p>
				  			<p><span>商品类目：</span>匹配与该商品相关的分类，方便用户搜索到该商品</p>
				  			<p><span>品牌：</span>品牌根据选中的一级类目进行搜索，默认是‘无’</p>
				  			<p><span>联系方式：</span>联系方式是卖家与买家之间的交易联系方式，买家在预订商品时通过手机短信和平台通知互相公开对方预留的联系方式，目前只提供三种联系（手机、微信、QQ）</p>
				  			<p><span>学校定位：</span>因为本平台只起到帮助用户发布商品，没有物流服务。只能通过学校内面对面交易，所以学校定位必须是您要进行面对面交易的学校</p>
				  			<p><span>宝贝介绍：</span>宝贝介绍中支持图片，视频（有些视频格式不支持），文字等等的详细介绍</p>
				  		</div><!-- release-goods-shuoming -->
				  		
				  	</div><!-- release-goods-left -->
				  	
				  	<!-- release-goods-right -->
				  	<div class="release-goods-right">
				  		<form class="layui-form layui-form-pane" action="${pageContext.request.contextPath}/goods/insertGoods" id="rgoodsform" method="post" enctype="multipart/form-data">
							  <div class="layui-form-item">
							    <label class="layui-form-label">商品标题</label>
							    <div class="layui-input-block">
							      <input type="text" id="goodsTitle" name="goodsTitle" autocomplete="off" placeholder="请商品标题" class="layui-input">
							    </div>
							  </div>
							  
							  <div class="layui-form-item">
							    <label class="layui-form-label">商品类目</label>
							    <div class="layui-input-inline">
							      <select id="oneMenuId" name="oneMenuId" lay-filter="oneMenuId">
							        <option value="0">请选择一级类目</option>
							        <c:forEach items="${cshtOneMenuList}" var="cshtOneMenuList">
							        	<option value="${cshtOneMenuList.oneMenuId}">${cshtOneMenuList.oneMenuName}</option>
							        </c:forEach>
							      </select>
							    </div>
							    <div class="layui-input-inline">
							      <select id="twoMenuId" name="twoMenuId" lay-filter="twoMenuId">
							      	<option value="0">请选择二级类目</option>
							      </select>
							    </div>
							    <div class="layui-input-inline">
							      <select id="threeMenuId" name="threeMenuId">
							      	<option value="0">请选择三级类目</option>
							      </select>
							    </div>
							  </div>
							  
							  <div class="layui-form-item">
							    <label class="layui-form-label">品牌</label>
							    <div class="layui-input-inline">
							      <select id="brandId" name="brandId">
							        <option value="0">请选择品牌</option>
							      </select>
							    </div>
							  </div>
							  
							  <div class="layui-form-item">
							    <div class="layui-inline">
							      <label class="layui-form-label">商品类型</label>
							      <div class="layui-input-inline" style="width: 100px;">
							        <input type="checkbox" title="二手" lay-skin="primary" disabled checked> 
							      </div>
							    </div>
							  </div>
							  
							  <div class="layui-form-item">
							    <div class="layui-inline">
							      <label class="layui-form-label">交易方式</label>
							      <div class="layui-input-inline" style="width: 100px;">
							      	<input type="checkbox" title="面对面" lay-skin="primary" disabled checked> 
							      </div>
							    </div>
							  </div>
							  
							  <div class="layui-form-item">
							    <div class="layui-inline">
							      <label class="layui-form-label">售价</label>
							      <div class="layui-input-inline" style="width: 100px;">
							        <input type="number" id="goodsPrice" name="goodsPrice" placeholder="￥" autocomplete="off" class="layui-input">
							      </div>
							    </div>
							  </div>
							  
							  <div class="layui-form-item">
							    <label class="layui-form-label">联系方式</label>
							    <div class="layui-input-block" id="telweChatqqdiv">
							      <input type="checkbox" id="tel" name="tel" title="手机">
							      <input type="checkbox" id="weChat" name="weChat" title="微信">
							      <input type="checkbox" id="qq" name="qq" title="QQ">
							      <input type="hidden" id="goodsTradeWay" name="goodsTradeWay" value="">
							    </div>
							  </div>
							  
							  <div class="layui-form-item">
							    <label class="layui-form-label">学校定位</label>
							    <div class="layui-input-inline">
							      <select id="rg-province" lay-filter="rg-province">
							        <option value="0">请选择省</option>
							        <c:forEach items="${provinceList}" var="provinceList">
							        	<option value="${provinceList.id}">${provinceList.name}</option>
							        </c:forEach>
							      </select>
							    </div>
							    <div class="layui-input-inline">
							      <select id="rg-city" lay-filter="rg-city">
							        <option value="0">请选择市</option>
							      </select>
							    </div>
							    <div class="layui-input-inline">
							      <select id="rg-school">
							        <option value="0">请选择学校</option>
							      </select>
							    </div>
							    <input type="hidden" id="goodsTradeSchool" name="goodsTradeSchool" value="">
							  </div>
							  
							  <div class="layui-form-item layui-form-text rgoods-img-text">
							    <label class="layui-form-label">上传商品图（至少上传1张，最多上传6张,可将一张图设置为商品封面图，默认是第一张）</label>
							    <div class="layui-input-block rgoods-img-block">
							      <input type="hidden" id="goodsImgpath" name="goodsImgpath" value="1">
							      <div class="rgoods-img">
							      	<input type="file" title="点击上传商品图" name="goodsimg" accept="image/gif,image/jpeg,image/png,image/jpg">
							      	<img src="" alt="商品图">
							      	<span class="glyphicon glyphicon-plus add-font"></span>
							      	<span class="badge delete-img">X</span>
							      	<input type="hidden" value="1">
							      </div>
							      <div class="rgoods-img">
							      	<input type="file" title="点击上传商品图" name="goodsimg" accept="image/gif,image/jpeg,image/png,image/jpg">
							      	<img src="" alt="商品图">
							      	<span class="glyphicon glyphicon-plus add-font"></span>
							      	<span class="badge delete-img">X</span>
							      	<input type="hidden" value="2">
							      </div>
							      <div class="rgoods-img">
							      	<input type="file" title="点击上传商品图" name="goodsimg" accept="image/gif,image/jpeg,image/png,image/jpg">
							      	<img src="" alt="商品图">
							      	<span class="glyphicon glyphicon-plus add-font"></span>
							      	<span class="badge delete-img">X</span>
							      	<input type="hidden" value="3">
							      </div>
							      <div class="rgoods-img">
							      	<input type="file" title="点击上传商品图" name="goodsimg" accept="image/gif,image/jpeg,image/png,image/jpg">
							      	<img src="" alt="商品图">
							      	<span class="glyphicon glyphicon-plus add-font"></span>
							      	<span class="badge delete-img">X</span>
							      	<input type="hidden" value="4">
							      </div>
							      <div class="rgoods-img">
							      	<input type="file" title="点击上传商品图" name="goodsimg" accept="image/gif,image/jpeg,image/png,image/jpg">
							      	<img src="" alt="商品图">
							      	<span class="glyphicon glyphicon-plus add-font"></span>
							      	<span class="badge delete-img">X</span>
							      	<input type="hidden" value="5">
							      </div>
							      <div class="rgoods-img">
							      	<input type="file" title="点击上传商品图" name="goodsimg" accept="image/gif,image/jpeg,image/png,image/jpg">
							      	<img src="" alt="商品图">
							      	<span class="glyphicon glyphicon-plus add-font"></span>
							      	<span class="badge delete-img">X</span>
							      	<input type="hidden" value="6">
							      </div>
							    </div>
							  </div>
							  
							  <div class="layui-form-item layui-form-text">
							    <label class="layui-form-label">宝贝介绍</label>
							    <div class="layui-input-block">
							      <textarea placeholder="请输入内容" name="goodsContent" id="goodsContent" class="layui-textarea"></textarea>
							    </div>
							  </div>
							  
							  <div class="layui-form-item rgoods-smbtn">
							    <button class="layui-btn layui-btn-danger" id="rgoodsbtn" type="button">立即发布</button>
							  </div>
							</form>
				  	</div><!-- release-goods-right -->
				  </div><!-- layui-field-box -->
				</fieldset>
			</div><!-- release-goods -->
		</div>
		<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/static/ueditor/ueditor.config.js"></script>
    	<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/static/ueditor/ueditor.all.js"></script>
    	<script type="text/javascript" src="${pageContext.request.contextPath}/static/ueditor/lang/zh-cn/zh-cn.js"></script>
		<script type="text/javascript">
			$(document).ready(function(){
				
				//点击立即发布按钮
				$("#rgoodsbtn").on("click", function(){
					var goodsTitleBool = false;
					var oneMenuIdBool = false;
					var twoMenuIdBool = false;
					var threeMenuIdBool = false;
					var goodsPriceBool = false;
					var goodsTradeWayBool = false;
					var goodsTradeSchoolBool = false;
					var rgoodsImgBool = false;
					var goodsContentBool = false;
					//交易方式处理
					function goodsTradeWayvalidation(){
						var goodsTradeWay = "";
						for(var i = 0; i < $("#telweChatqqdiv div").length; i++){
							if($($("#telweChatqqdiv div")[i]).attr("class") == "layui-unselect layui-form-checkbox layui-form-checked"){
								goodsTradeWay += $($("#telweChatqqdiv input[type='checkbox']")[i]).attr("title") + "/";
							}
						}
						//给隐藏的交易方式赋值
						$("#goodsTradeWay").val(goodsTradeWay.substr(0, goodsTradeWay.length - 1));
					}
					goodsTradeWayvalidation();
					//交易学校处理
					function goodsTradeSchoolvalidation(){
						var rgprovincecvalId = $("#rg-province").val(); //获取省份id
						var rgprovincecval = $("#rg-province option[value='" + rgprovincecvalId + "']").text(); //获取省份
						var rgcityval = $("#rg-city").val(); //获取城市
						var rgschoolval = $("#rg-school").val(); //获取学校
						if(rgprovincecvalId != 0 && rgprovincecval != 0 && rgschoolval != 0){
							$("#goodsTradeSchool").val(rgprovincecval + "-" + rgcityval + "-" + rgschoolval);
						}else{
							$("#goodsTradeSchool").val("");
						}
					}
					goodsTradeSchoolvalidation();
					
					//商品标题校验
					if($("#goodsTitle").val().length < 10 || $("#goodsTitle").val().length > 50){
						layer.msg("商品标题要求10-50个字之间");
						goodsTitleBool = false;
						return;
					}else{
						goodsTitleBool = true;
					}
					//一级菜单校验
					if($("#oneMenuId").val() == 0){
						layer.msg("请选择一级类目");
						oneMenuIdBool = false;
						return;
					}else{
						oneMenuIdBool = true;
					}
					//二级菜单校验
					if($("#twoMenuId").val() == 0){
						layer.msg("请选择二级类目");
						twoMenuIdBool = false;
						return;
					}else{
						twoMenuIdBool = true;
					}
					//三级菜单校验
					if($("#threeMenuId").val() == 0){
						layer.msg("请选择三级类目");
						threeMenuIdBool = false;
						return;
					}else{
						threeMenuIdBool = true;
					}
					//售价校验
					if($("#goodsPrice").val() < 1 || $("#goodsPrice").val() == ""){
						layer.msg("售价不能小于1");
						goodsPriceBool = false;
						return;
					}else{
						goodsPriceBool = true;
					}
					//交易方式校验
					if($("#goodsTradeWay").val() == ""){
						layer.msg("至少选择一种交易方式");
						goodsTradeWayBool = false;
						return;
					}else{
						goodsTradeWayBool = true;
					}
					//学校定位校验
					if($("#goodsTradeSchool").val() == ""){
						layer.msg("请选择学校定位地址");
						goodsTradeSchoolBool = false;
						return;
					}else{
						goodsTradeSchoolBool = true;
					}
					//商品图片校验（至少一张图）
					function rgoodsImgValidation(){
						for(var i = 0; i < $(".rgoods-img-block .rgoods-img input[type='file']").length; i++){
							if($($(".rgoods-img-block .rgoods-img input[type='file']")[i]).val() != ""){
								rgoodsImgBool = true;
								break;
							}else if(i == $(".rgoods-img-block .rgoods-img input[type='file']").length - 1){
								layer.msg("至少要上传一张商品图片");
								rgoodsImgBool = false;
							}
						}
					}
					rgoodsImgValidation();
					if(rgoodsImgBool == false){
						return;
					}
					
					//宝贝介绍
					if(ue.getContent().length < 30){
						layer.msg("宝贝介绍不能少于30个字");
						goodsContentBool = false;
						return;
					}else{
						goodsContentBool = true;
					}
					
					//提交表单
					if(goodsTitleBool && oneMenuIdBool && twoMenuIdBool && threeMenuIdBool && 
							goodsPriceBool && goodsTradeWayBool && goodsTradeSchoolBool && 
							rgoodsImgBool && goodsContentBool){
						$("#rgoodsform").submit();
					}else{
						layer.open({
							  content: '商品发布出错，请联系管理员',
							  title: '提示:',
							  icon: 1,
							  anim: 6
						});
					}
				});
				
				//点击搜索类目
				$("#selected-buttom").on("click", function(){
					var threeMenuName = $(this).siblings("input").val(); //获取用户输入的搜索值
					if(threeMenuName == ""){
						layer.msg("请输入商品类别关键词");
					}else{
						$.ajax({
							url: "${pageContext.request.contextPath}/goods/getMenuToSearch",
							type: "POST",
							dataType: "json",
							data: {
								"threeMenuName": threeMenuName,
							},
							success: function(data){
								if(data.threeMenuVoList.length < 1){
									$(".pipei-type").html("<h6>匹配到以下类目：</h6><h6><b>无搜索结果</b></h6>");
								}else{
									var pipeiTypeHtml = "<h6>匹配到以下类目：</h6>";
									for(var i = 0; i < data.threeMenuVoList.length; i++){
										pipeiTypeHtml += "<p>" + data.threeMenuVoList[i].twoMenuVo.cshtOneMenu.oneMenuName + ">>" + data.threeMenuVoList[i].twoMenuVo.twoMenuName + ">>" + data.threeMenuVoList[i].threeMenuName + "</p>";
									}
									pipeiTypeHtml += "<button type='button'>确定匹配</button>";
									$(".pipei-type").html(pipeiTypeHtml);
								}
							}
						})
					}
					
				});
				
				//点击匹配类目
				$(".pipei-type").delegate("button", "click", function(){
					$("#oneMenuId option").removeAttr("selected"); //初始化一级类目
					$("#twoMenuId option").removeAttr("selected"); //初始化二级类目
					$("#threeMenuId option").removeAttr("selected"); //初始化三级类目
					var pipeival = $(this).siblings("p[class='xuanzhong']").text(); //获取选中的
					var menusplit = pipeival.split(">>"); //分割
					for(var i = 0; i < $("#oneMenuId option").length; i++){ //遍历一级菜单
						if($($("#oneMenuId option")[i]).text() == menusplit[0]){ //判断值是否相同，相同则选中
							$($("#oneMenuId option")[i]).attr("selected", "selected");
							var oneMenuId = $($("#oneMenuId option")[i]).val();
							$.ajax({ //根据一级菜单id查找二级菜单
				    			url: "${pageContext.request.contextPath}/goods/getTowMenuAndBrandByOneMenuId",
				    			type: "post",
				    			dataType: "json",
				    			data: {
				    				"oneMenuId": oneMenuId
				    			},
				    			success:function(data){
				    				var twoMenuIdHtml = "<option value='0'>请选择二级类目</option>";
				    				var brandIdHtml = "";
				    				for(var i = 0; i < data.cshtTwoMenuList.length; i++){
				    					if(menusplit[1] != data.cshtTwoMenuList[i].twoMenuName){ //判断类目相等则选中状态
				    						twoMenuIdHtml += "<option value='" + data.cshtTwoMenuList[i].twoMenuId + "'>" + data.cshtTwoMenuList[i].twoMenuName + "</option>";
				    					}else{
				    						twoMenuIdHtml += "<option value='" + data.cshtTwoMenuList[i].twoMenuId + "' selected>" + data.cshtTwoMenuList[i].twoMenuName + "</option>";
				    					}
				    					
				    				}
				    				for(var i = 0; i < data.cshtBrandList.length; i++){
				    					if(data.cshtBrandList[i].brandName == "无"){
				    						brandIdHtml += "<option value='" + data.cshtBrandList[i].brandId + "' selected>" + data.cshtBrandList[i].brandName + "</option>";
				    					}else{
				    						brandIdHtml += "<option value='" + data.cshtBrandList[i].brandId + "'>" + data.cshtBrandList[i].brandName + "</option>";
				    					}
				    				}
				    				$("#twoMenuId").html(twoMenuIdHtml);
				    				$("#brandId").html(brandIdHtml);
				    				$("#threeMenuId").html("<option value='0'>请选择三级类目</option>");
				    				layui.form.render("select"); //渲染下拉框
				    				
				    				for(var i = 0; i < $("#twoMenuId option").length; i++){ //遍历二级菜单
										if($($("#twoMenuId option")[i]).text() == menusplit[1]){ //判断值是否相同，相同则选中
											$($("#twoMenuId option")[i]).attr("selected", "selected");
											var twoMenuId = $($("#twoMenuId option")[i]).val();
											$.ajax({ //根据二级菜单id查找三级菜单
								    			url: "${pageContext.request.contextPath}/goods/getThreeMenuByTwoMenuId",
								    			type: "post",
								    			dataType: "json",
								    			data: {
								    				"twoMenuId": twoMenuId
								    			},
								    			success:function(data){
								    				var threeMenuIdHtml = "<option value='0'>请选择三级类目</option>";
								    				for(var i = 0; i < data.cshtThreeMenuList.length; i++){
								    					if(menusplit[2] != data.cshtThreeMenuList[i].threeMenuName){ //判断类目相等则选中状态
								    						threeMenuIdHtml += "<option value='" + data.cshtThreeMenuList[i].threeMenuId + "'>" + data.cshtThreeMenuList[i].threeMenuName + "</option>";
								    					}else{
								    						threeMenuIdHtml += "<option value='" + data.cshtThreeMenuList[i].threeMenuId + "' selected>" + data.cshtThreeMenuList[i].threeMenuName + "</option>";
								    					}
								    				}
								    				$("#threeMenuId").html(threeMenuIdHtml);
								    				layui.form.render("select"); //渲染下拉框
								    			}
								    		});
											break;
										}
									}
				    			}
				    		});
							break;
						}
					}
					layer.msg("匹配成功");
				});
				
				//根据一级菜单变化查找二菜单和品牌
				layui.form.on("select(oneMenuId)", function(data){
					var oneMenuId = data.value; //一级菜单id
		    		$.ajax({
		    			url: "${pageContext.request.contextPath}/goods/getTowMenuAndBrandByOneMenuId",
		    			type: "post",
		    			dataType: "json",
		    			data: {
		    				"oneMenuId": oneMenuId
		    			},
		    			success:function(data){
		    				var twoMenuIdHtml = "<option value='0'>请选择二级类目</option>";
		    				var brandIdHtml = "";
		    				for(var i = 0; i < data.cshtTwoMenuList.length; i++){
		    					twoMenuIdHtml += "<option value='" + data.cshtTwoMenuList[i].twoMenuId + "'>" + data.cshtTwoMenuList[i].twoMenuName + "</option>";
		    				}
		    				for(var i = 0; i < data.cshtBrandList.length; i++){
		    					if(data.cshtBrandList[i].brandName == "无"){
		    						brandIdHtml += "<option value='" + data.cshtBrandList[i].brandId + "' selected>" + data.cshtBrandList[i].brandName + "</option>";
		    					}else{
		    						brandIdHtml += "<option value='" + data.cshtBrandList[i].brandId + "'>" + data.cshtBrandList[i].brandName + "</option>";
		    					}
		    				}
		    				$("#twoMenuId").html(twoMenuIdHtml);
		    				$("#brandId").html(brandIdHtml);
		    				$("#threeMenuId").html("<option value='0'>请选择三级类目</option>");
		    				layui.form.render("select"); //渲染下拉框
		    			}
		    		})
		    	});
				
				//根据二级菜单变化查找三菜单
				layui.form.on("select(twoMenuId)", function(data){
					var twoMenuId = data.value; //二级菜单id
		    		$.ajax({
		    			url: "${pageContext.request.contextPath}/goods/getThreeMenuByTwoMenuId",
		    			type: "post",
		    			dataType: "json",
		    			data: {
		    				"twoMenuId": twoMenuId
		    			},
		    			success:function(data){
		    				var threeMenuIdHtml = "<option value='0'>请选择三级类目</option>";
		    				for(var i = 0; i < data.cshtThreeMenuList.length; i++){
		    					threeMenuIdHtml += "<option value='" + data.cshtThreeMenuList[i].threeMenuId + "'>" + data.cshtThreeMenuList[i].threeMenuName + "</option>";
		    				}
		    				$("#threeMenuId").html(threeMenuIdHtml);
		    				layui.form.render("select"); //渲染下拉框
		    			}
		    		})
		    	});
				
				
				//根据省id变化查找城市
				layui.form.on("select(rg-province)", function(data){
		    		var rgprovinceId = data.value; //省id
		    		$.ajax({
		    			url: "${pageContext.request.contextPath}/goods/getAllCityByProvinceId",
		    			type: "post",
		    			dataType: "json",
		    			data: {
		    				"provinceId": rgprovinceId
		    			},
		    			success:function(data){
		    				var rgcityHtml = "<option value='0'>请选择城市</option>";
		    				for(var i = 0; i < data.cityList.length; i++){
		    					rgcityHtml += "<option value='" + data.cityList[i] + "'>" + data.cityList[i] + "</option>";
		    				}
		    				$("#rg-city").html(rgcityHtml);
		    				$("#rg-school").html("<option value='0'>请选择学校</option>");
		    				layui.form.render("select"); //渲染下拉框
		    			}
		    		})
		    	});
				
				//根据城市名变化查找学校
				layui.form.on("select(rg-city)", function(data){
		    		var rgcityName = data.value; //城市名
		    		$.ajax({
		    			url: "${pageContext.request.contextPath}/goods/getAllSchoolByCityName",
		    			type: "post",
		    			dataType: "json",
		    			data: {
		    				"cityName": rgcityName
		    			},
		    			success:function(data){
		    				var rgschoolHtml = "<option value='0'>请选择学校</option>";
		    				for(var i = 0; i < data.schoolList.length; i++){
		    					rgschoolHtml += "<option value='" + data.schoolList[i].name + "'>" + data.schoolList[i].name + "</option>";
		    				}
		    				$("#rg-school").html(rgschoolHtml);
		    				layui.form.render("select"); //渲染下拉框
		    			}
		    		})
		    	});
				
				//上传商品图预览
				$(".rgoods-img input[type='file']").on("change", function(){
					var imgFile = this.files[0];//获取图片
					var img = $(this).siblings("img"); //获取同级的img
					var deleteimg = $(this).siblings(".delete-img"); //获取同级的class='delete-img'
					deleteimg.hide(); //隐藏同级的class='delete-img'
					img.hide(); //隐藏同级的class='delete-img'
					$(this).siblings(".imgbutton").remove(); //删除同级的class='imgbutton'元素
					if(imgFile.size > 1024 * 1024 * 3){
						layer.msg('图片大小不能超过3M');
						$(this).val() = "";
						return;
					}else{
						var filereader = new FileReader();
						filereader.readAsDataURL(imgFile);//读取图片
						filereader.onload = function() {//读取完成时预览
							img.attr("src",filereader.result);
							};
						deleteimg.show(); //显示删除图片小按钮
						img.show(); //显示图片
						//添加元素
						$(this).parent().append("<div class='imgbutton'><button type='button' class='layui-btn layui-btn-xs layui-btn-danger'>设置为封面</button></div>");
					}
				});
				
				//点击删除图片
				$(".rgoods-img .delete-img").on("click", function(){
					$(this).siblings("input[type='file']").val(""); //初始化input
					$(this).siblings("img").attr("src", ""); //初始化img
					$(this).siblings("img").hide(); //隐藏img
					$(this).siblings(".imgbutton").remove(); //删除同级的class='imgbutton'元素
					$(this).hide(); //隐藏删除图片小按钮
					//判断删除的图片是否为设置为封面的图，是则进行初始化
					var userxzimgId = $("#goodsImgpath").val();
					var thisimgId = $(this).siblings("input[type='hidden']").val();
					if(userxzimgId == thisimgId){
						$("#goodsImgpath").val(1);
					}
				});
				
				//点击设置为封面图
				$(".rgoods-img").delegate(".imgbutton button", "click", function(){
					$(".imgbutton button").attr("class", "layui-btn layui-btn-xs layui-btn-danger"); //去掉禁止点击
					$(".imgbutton button").text("设置为封面");
					//标记用户是设置第几张图为封面图
					$("#goodsImgpath").val($(this).parent().siblings("input[type='hidden']").val());
					$(this).attr("class", "layui-btn layui-btn-xs layui-btn-disabled"); //设置被点击的按钮禁止点击
					$(this).text("已设置");
				});
								
				//开启百度编辑器
				var ue = UE.getEditor('goodsContent');
				
				//点击匹配的类目，变成选中状态
				$(".release-goods .pipei-type").delegate("p", "click", function(){
					$(".release-goods .pipei-type p").removeClass("xuanzhong");
					$(this).addClass("xuanzhong");
				});
				
				//layui渲染表单样式
				layui.use(['form'],function(){
				   var form=layui.form;
				   form.render();
				});
				
				
			})
		</script>
		
		
	</body>
</html>